Skip to content

Conversation

@berler
Copy link
Contributor

@berler berler commented Mar 7, 2023

Before this PR

Jooq provides multiple methods to execute queries in batches. Some of these methods end up executing queries without bind args which can cause performance problems.

After this PR

Disallow jOOQ's batch methods that execute queries without bind args. Batch methods that do use bind args should be used instead.

==COMMIT_MSG==
Add error-prone check JooqBatchWithoutBindArgs
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Mar 7, 2023

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Add error-prone check JooqBatchWithoutBindArgs

Check the box to generate changelog(s)

  • Generate changelog entry

@berler berler force-pushed the berler/jooq-batch-without-binds branch from 3581cdc to d36cbed Compare March 8, 2023 17:34
Comment on lines 51 to 52
private static final String ERROR_MESSAGE =
"Jooq batch methods that execute queries without bind args cause performance problems.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if @lukaseder has guidance on this?

@berler It would be helpful if you could provide more information. How do we ensure this remains true over time? Do you have public benchmarking data to substantiate the claim?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have public benchmarking data, but we do know that the way this executes is using extra CPU on the database because each query is sent over as a unique string (with all variable values inline as a string in the query). There is CPU overhead parsing and query planning each query in the batch.

Looking at how we we have used jooq internally, it was actually surprising to most of our dev teams how these calls were being executed. People usually use the batch methods to execute the same query hundreds to thousands of times but just with different bind variables. What we want to happen (and what most of our devs thought was actually happening) is it sends the query to the DB once and then just sends the arrays of bind args to execute the same query with each set of bind variables. Internally we've already refactored nearly all of our code to use the other batch methods that execute with bind args.

Copy link

@CVdV-au CVdV-au left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR please!

@bulldozer-bot bulldozer-bot bot merged commit 28e2069 into develop Mar 15, 2023
@bulldozer-bot bulldozer-bot bot deleted the berler/jooq-batch-without-binds branch March 15, 2023 01:55
@svc-autorelease
Copy link
Collaborator

Released 4.191.0

bulldozer-bot bot pushed a commit to palantir/witchcraft-api that referenced this pull request Mar 15, 2023
###### _excavator_ is a bot for automating changes across repositories.

Changes produced by the roomba/latest-baseline-oss check.

# Release Notes
## 4.191.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Feature | Add error-prone check JooqBatchWithoutBindArgs | palantir/gradle-baseline#2506 |



To enable or disable this check, please contact the maintainers of Excavator.
This was referenced Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants